package cn.cvs.utils;

import java.math.BigDecimal;

public class BigDecimalUtil {
    public BigDecimalUtil() {
    }

    public static BigDecimal OperationASMD(Object numOne, Object numTwo, BigDecimalUtil.BigDecimalOprations bigDecimalOpration, int scale, int roundingMode) throws Exception {
        BigDecimal num1 = (new BigDecimal(String.valueOf(numOne))).setScale(scale, roundingMode);
        BigDecimal num2 = (new BigDecimal(String.valueOf(numTwo))).setScale(scale, roundingMode);
        switch(bigDecimalOpration) {
            case add:
                return num1.add(num2).setScale(scale, roundingMode);
            case subtract:
                return num1.subtract(num2).setScale(scale, roundingMode);
            case multiply:
                return num1.multiply(num2).setScale(scale, roundingMode);
            case divide:
                return num1.divide(num2, scale, roundingMode);
            default:
                return null;
        }
    }

    public static void main(String[] args) {
        try {
            System.out.println(OperationASMD(36.23D, 23.369D, BigDecimalUtil.BigDecimalOprations.add, 2, 1));
            System.out.println(OperationASMD("36.23", "23.369", BigDecimalUtil.BigDecimalOprations.add, 2, 1));
            System.out.println(OperationASMD(36, 23, BigDecimalUtil.BigDecimalOprations.add, 2, 1));
            System.out.println(OperationASMD(36L, 69L, BigDecimalUtil.BigDecimalOprations.add, 2, 1));
            System.out.println(OperationASMD(new BigDecimal(0.2635D), new BigDecimal(2.3568D), BigDecimalUtil.BigDecimalOprations.add, 2, 1));
            System.out.println(OperationASMD(36.23D, 23.369D, BigDecimalUtil.BigDecimalOprations.subtract, 2, 1));
            System.out.println(OperationASMD("36.23", "23.369", BigDecimalUtil.BigDecimalOprations.subtract, 2, 1));
            System.out.println(OperationASMD(36, 23, BigDecimalUtil.BigDecimalOprations.subtract, 2, 1));
            System.out.println(OperationASMD(36L, 69L, BigDecimalUtil.BigDecimalOprations.subtract, 2, 1));
            System.out.println(OperationASMD(new BigDecimal(0.2635D), new BigDecimal(2.3568D), BigDecimalUtil.BigDecimalOprations.subtract, 2, 1));
            System.out.println(OperationASMD(36.23D, 23.369D, BigDecimalUtil.BigDecimalOprations.multiply, 2, 1));
            System.out.println(OperationASMD("36.23", "23.369", BigDecimalUtil.BigDecimalOprations.multiply, 2, 1));
            System.out.println(OperationASMD(36, 23, BigDecimalUtil.BigDecimalOprations.multiply, 2, 1));
            System.out.println(OperationASMD(36L, 69L, BigDecimalUtil.BigDecimalOprations.multiply, 2, 1));
            System.out.println(OperationASMD(new BigDecimal(0.2635D), new BigDecimal(2.3568D), BigDecimalUtil.BigDecimalOprations.multiply, 2, 1));
            System.out.println(OperationASMD(36.23D, 23.369D, BigDecimalUtil.BigDecimalOprations.divide, 2, 1));
            System.out.println(OperationASMD("36.23", "23.369", BigDecimalUtil.BigDecimalOprations.divide, 2, 1));
            System.out.println(OperationASMD(36, 23, BigDecimalUtil.BigDecimalOprations.divide, 2, 1));
            System.out.println(OperationASMD(36L, 69L, BigDecimalUtil.BigDecimalOprations.divide, 2, 1));
            System.out.println(OperationASMD(new BigDecimal(0.235D), new BigDecimal(0.5689D), BigDecimalUtil.BigDecimalOprations.divide, 2, 1));
        } catch (Exception var2) {
            var2.printStackTrace();
        }

    }

    static enum BigDecimalOprations {
        add,
        subtract,
        multiply,
        divide;

        private BigDecimalOprations() {
        }
    }
}
